﻿using System.Windows.Forms;
using CloudShot.Entities;

namespace CloudShot.Utils
{
  internal static class HotkeyUtils
  {
    public static KeyModifiers GetModifiers(this KeyEventArgs keyEventArgs)
    {
      var result = KeyModifiers.None;
      if (keyEventArgs.Alt)
        result |= KeyModifiers.Alt;

      if (keyEventArgs.Control)
        result |= KeyModifiers.Ctrl;

      if (keyEventArgs.Shift)
        result |= KeyModifiers.Shift;

      return result;
    }

    public static Hotkey BuildFullHotkey(this Keys fullKeys)
    {
      var modifier = KeyModifiers.None;
      if ((fullKeys & Keys.Alt) != 0)
      {
        modifier |= KeyModifiers.Alt;
        fullKeys ^= Keys.Alt;
      }

      if ((fullKeys & Keys.Control) != 0)
      {
        modifier |= KeyModifiers.Ctrl;
        fullKeys ^= Keys.Control;
      }

      if ((fullKeys & Keys.Shift) != 0)
      {
        modifier |= KeyModifiers.Shift;
        fullKeys ^= Keys.Shift;
      }
      return new Hotkey(fullKeys, modifier);
    }
  }
}